package org.example.src.repository;

import org.example.src.entity.Student;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface StudentRepository extends JpaRepository<Student, Long> {
    Optional<Student> findByStudentId(String studentId);

    @Query("SELECT s FROM Student s WHERE s.major = :major")
    List<Student> findByMajor(@Param("major") String major);

    @Query("SELECT s FROM Student s WHERE s.grade = :grade")
    List<Student> findByGrade(@Param("grade") Integer grade);

    @Query("SELECT s FROM Student s WHERE s.className = :className")
    List<Student> findByClassName(@Param("className") String className);

    @Query("SELECT s FROM Student s WHERE s.fullName LIKE %:name%")
    List<Student> findByNameContaining(@Param("name") String name);

    @Query("SELECT COUNT(s) FROM Student s")
    Long countAllStudents();
}